//
//  PushSurveyPreviewViewController.m
//  Ai
//
//  Created by 杜超男 on 2019/3/7.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "PushSurveyPreviewViewController.h"
#import "PushTableViewCell.h"
#import "PushParticularsViewController.h"
@interface PushSurveyPreviewViewController ()<UITableViewDelegate , UITableViewDataSource>
{
//    NSString *weekmustr;
    
    NSArray *class;
    NSArray *manager;
    NSArray *vip;
    NSArray *nopush;
    NSDateFormatter *Dateformatter;
    NSString *nyrzString;
    NSString *dateStr_yyyy;
    NSString *dateStr_MM;
    NSString *dateStr_dd;
    NSString *dateStr_EEEE;
}
@property (nonatomic , strong)NSDateFormatter *formatter;
@property (nonatomic , strong)NSDate *currentDate;
@property (nonatomic , strong)UITableView *tableView;
@property (nonatomic , strong)NSMutableArray *DataSoure;

@end

@implementation PushSurveyPreviewViewController
- (void)date_yyyy{
    //获取年月日
    [Dateformatter setDateFormat:@"yyyy"];
    dateStr_yyyy = [Dateformatter stringFromDate:self.currentDate];
}
- (void)date_MM{
    [Dateformatter setDateFormat:@"MM"];
//    self.currentDate = [NSDate date];
    dateStr_MM = [Dateformatter stringFromDate:self.currentDate];
}
- (void)date_dd{
    [Dateformatter setDateFormat:@"dd"];
//    self.currentDate = [NSDate date];
    dateStr_dd = [Dateformatter stringFromDate:self.currentDate];
}
- (void)date_EEEE{
    [Dateformatter setDateFormat:@"EEEE"];
    dateStr_EEEE = [Dateformatter stringFromDate:self.currentDate];
    if ([dateStr_EEEE isEqualToString:@"Monday"]) {
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周一";
    }else if ([dateStr_EEEE isEqualToString:@"Tuesday"]){
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周二";
    }else if ([dateStr_EEEE isEqualToString:@"Wednesday"]){
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周三";
    }else if ([dateStr_EEEE isEqualToString:@"Thursday"]){
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周四";
    }else if ([dateStr_EEEE isEqualToString:@"Friday"]){
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周五";
    }else if ([dateStr_EEEE isEqualToString:@"Saturday"]){
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周六";
    }else if ([dateStr_EEEE isEqualToString:@"Sunday"]){
        dateStr_EEEE = [[NSString alloc] init];
        dateStr_EEEE = @"周日";
    }
}
- (void)date_nyr{
    nyrzString = [NSString stringWithFormat:@"%@-%@-%@ %@",dateStr_yyyy , dateStr_MM , dateStr_dd , dateStr_EEEE];
    NSLog(@"%@",nyrzString);
    self.DateLabel.text = nyrzString;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    Dateformatter = [[NSDateFormatter alloc] init];
    self.currentDate = [[NSDate alloc] init];
    
    [self date_yyyy];
    [self date_MM];
    [self date_dd];
    [self date_EEEE];
    [self date_nyr];
    
    [self.view addSubview:self.tableView];
    self.DataSoure = [[NSMutableArray alloc] init];
    class = [[NSArray alloc] initWithObjects:@"小1班" , @"小小班" , @"芒果班" , @"小可爱" , @"蒙台梭利1班" , @"草莓班", nil];
    manager = [[NSArray alloc] initWithObjects:@"刘庆" , @"上官晓晓" , @"张浩然" , @"上官晓晓" , @"张浩然" , @"上官晓晓", nil];
    vip = [[NSArray alloc] initWithObjects:@"20" , @"15" , @"30" , @"56" , @"56" , @"89", nil];
    nopush = [[NSArray alloc] initWithObjects:@"5" , @"6" , @"3" , @"1" , @"3" , @"4", nil];
    [self.DataSoure addObjectsFromArray:@[class, manager, vip , nopush]];
    // Do any additional setup after loading the view from its nib.
}
-(UITableView *)tableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width+80, self.view.frame.size.height-80) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"PushTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    return _tableView;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return class.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PushTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[PushTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    cell.ClassName.text = class[indexPath.row];
    cell.ManagerMan.text = manager[indexPath.row];
    cell.VIPNumber.text = vip[indexPath.row];
    cell.NOPushNumber.text = nopush[indexPath.row];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
    //
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(53, 16, 80, 12)];
    label1.text = @"班级";
    label1.font = [UIFont systemFontOfSize:12];
    label1.textColor = [UIColor blackColor];
    [headerView addSubview:label1];
    //
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(130, 16, 100, 12)];
    label2.font = [UIFont systemFontOfSize:12];
    label2.text = @"班级管理员";
    label2.textColor = [UIColor blackColor];
    [headerView addSubview:label2];
    //
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(220, 16, 100, 12)];
    label3.text = @"VIP用户(人)";
    label3.font = [UIFont systemFontOfSize:12];
    label3.textColor = [UIColor blackColor];
    [headerView addSubview:label3];
    //
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(320, 16, 100, 12)];
    label4.text = @"当日未推送";
    label4.font = [UIFont systemFontOfSize:12];
    label4.textColor = [UIColor blackColor];
    [headerView addSubview:label4];
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
- (IBAction)DateBtn:(id)sender {
    
}
- (IBAction)AgoBtn:(id)sender {
    self.currentDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:([self.currentDate timeIntervalSinceReferenceDate]-24*3600)];
    dateStr_MM = [Dateformatter stringFromDate:self.currentDate];
    [self date_yyyy];
    [self date_MM];
    [self date_dd];
    [self date_EEEE];
    [self date_nyr];
    
}
- (IBAction)LastBtn:(id)sender {
    self.currentDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:([self.currentDate timeIntervalSinceReferenceDate]+24*3600)];
    dateStr_MM = [Dateformatter stringFromDate:self.currentDate];
    [self date_yyyy];
    [self date_MM];
    [self date_dd];
    [self date_EEEE];
    [self date_nyr];
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.navigationController pushViewController:[PushParticularsViewController new] animated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
